//
//  SectorMenuController.m
//  oc1
//
//  Created by kokuma on 2017/2/21.
//  Copyright © 2017年 kokumams. All rights reserved.
//

#import "SectorMenuController.h"
#import "UIColor+expanded.h"
#import "NSObject+Common.h"

@interface SectorMenuController ()
@property (readwrite, nonatomic, strong) NSString  *myTitle, *content;
@property (nonatomic, strong) UIButton *menuBottom, *menuItem1, *menuItem2;
@end

@implementation SectorMenuController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.menuItem1];
    [self.view addSubview:self.menuItem2];
    [self.view addSubview:self.menuBottom];
   
    //[UIButton buttonWithStyle:StrapSuccessStyle andTitle:@"点我点我" andFrame:CGRectMake(100, 60, 100, 50) target:self action:@selector(sendActivate)];
}

- (void)menuItemClick:(id) sender{
    UIButton *item = sender;
    if(item.tag==0){
        [self animAllItems1];
    }else{
        [NSObject showHudTipStr:@"menuItemClick"];
    }
}

-(void)animAllItems1{
    NSLog(@"animAllItems1");
//    [UIView animateWithDuration:3 animations:^{
//        self.menuItem1.frame=CGRectMake(20,150, 100,100);
//    }];
    
    
    [UIView beginAnimations:@"move" context:nil];
    
    [UIView setAnimationDuration:0.8];
    
    //[UIView setAnimationDelegate:self];
    //改变它的frame的x,y的值
    _menuItem1.frame=CGRectMake(20,150, 100,100);
    _menuItem2.frame=CGRectMake(120,109, 100,100);
    _menuItem1.alpha=0;
    _menuItem2.alpha=0;
    [UIView commitAnimations];
}

-(void)animAllItems2{
     NSLog(@"animAllItems2");
    [UIView animateWithDuration:15 delay:0 options:UIViewAnimationOptionCurveLinear animations:^(void){
        self.menuItem1.frame=CGRectMake(20,150, 100,100);
        self.menuItem2.frame=CGRectMake(120,109, 100,100);
        //self.menuItem1.alpha=0.1;
       // self.menuItem2.alpha=0.1;
        }completion:^(BOOL finished){
//    [UIView animateWithDuration:1 delay:1.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
//                    animations:^(void){
//                    [UIView setAnimationRepeatCount:2.5];
//                     
//                    }completion:^(BOOL finished){}];
            
    }];
}

-(void)animAllItems3{
     NSLog(@"animAllItems3");
    CABasicAnimation *animPos1 = [CABasicAnimation animationWithKeyPath:@"position"];
    CABasicAnimation *animPos2 = [CABasicAnimation animationWithKeyPath:@"position"];
    CABasicAnimation *animOpacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
    CAAnimationGroup *animationgroup1 = [CAAnimationGroup animation];
    CAAnimationGroup *animationgroup2 = [CAAnimationGroup animation];
    animPos1.fromValue = [NSValue valueWithCGPoint:self.menuBottom.center];
    animPos1.toValue = [NSValue valueWithCGPoint:CGPointMake(self.menuBottom.center.x-100, self.menuBottom.center.y-100)];
    animPos2.fromValue = [NSValue valueWithCGPoint:self.menuBottom.center];
    animPos2.toValue = [NSValue valueWithCGPoint:CGPointMake(self.menuBottom.center.x, self.menuBottom.center.y-141)];
    animationgroup1.animations=@[animPos1, animOpacity];
    animationgroup1.duration = 0.5f;
    animationgroup1.fillMode = kCAFillModeForwards;
    animationgroup1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    [self.menuItem1.layer addAnimation:animationgroup1 forKey:@"Expand"];
     //self.menuItem1.center = self.menuItem1.endPoint;
}

- (UIButton *) menuBottom{
    _menuBottom = [[UIButton alloc] initWithFrame:CGRectMake(120, 250, 100, 100)];
    [_menuBottom setTag:0];
    _menuBottom.backgroundColor = [UIColor orangeColor];
    [_menuBottom addTarget:self action:@selector(menuItemClick:) forControlEvents:UIControlEventTouchUpInside];
    return _menuBottom;}

- (UIButton *) menuItem1{
    _menuItem1 = [[UIButton alloc] initWithFrame:CGRectMake(120, 250, 50, 50)];
    [_menuItem1 setTag:1];
    _menuItem1.backgroundColor = [UIColor greenColor];
    [_menuItem1 addTarget:self action:@selector(menuItemClick:) forControlEvents:UIControlEventTouchUpInside];
    return _menuItem1;
}

- (UIButton *) menuItem2{
    _menuItem2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 250, 50, 50)];
    [_menuItem2 setTag:2];
    _menuItem2.backgroundColor = [UIColor cyanColor];
    [_menuItem2 addTarget:self action:@selector(menuItemClick:) forControlEvents:UIControlEventTouchUpInside];
    return _menuItem2;
}
@end
